#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage: $0 number_of_tests"
	exit
fi

number_of_tests=$1

generation=0.0;
solution=0.0;
real_time=0.0;

for (( i=0 ; i<number_of_tests ; i++ ))
do
	time_before=`date +%s`
	./o | tail -n 2 > result
	time_after=`date +%s`
	real_time=`echo $real_time + $time_after - $time_before | bc`

	var=`cat result | cut -d ' ' -f 2|head -n 1`
	generation=`echo $generation + $var | bc`
	var=`cat result | cut -d ' ' -f 2|tail -n 1`
	solution=`echo $solution + $var | bc`
done

generation=`echo "scale=2; $generation / $number_of_tests" | bc`
solution=`echo "scale=2; $solution / $number_of_tests" | bc`
real_time=`echo "scale=2; $real_time / $number_of_tests" | bc`
#solution=`echo scale=4; ${solution} | bc`

echo "Results from $number_of_tests execution(s):"
echo "	average generation: $generation"
echo "	average solution: $solution"
echo "	average time: $real_time seconds"
